
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/tensor/tensor.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:08 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Tensor &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="tensor.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Tensor Operators" href="toperators.html" />
    <link rel="prev" title="Methods" href="index_methods.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="toperators.html" title="Tensor Operators"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index_methods.html" title="Methods"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Tensor</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Tensor</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.tensor.tensor">
<span id="tensor"></span><span id="tensor-tensor"></span><h1>Tensor<a class="headerlink" href="#module-sympy.tensor.tensor" title="Permalink to this headline">¶</a></h1>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorIndexType">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensorIndexType</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dummy_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dim</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">eps_dim</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">metric_symmetry</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">metric_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'metric'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L931-L1202"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorIndexType" title="Permalink to this definition">¶</a></dt>
<dd><p>A TensorIndexType is characterized by its name and its metric.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>name</strong> : name of the tensor type</p>
<p><strong>dummy_name</strong> : name of the head of dummy indices</p>
<p><strong>dim</strong> : dimension, it can be a symbol or an integer or <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p><strong>eps_dim</strong> : dimension of the epsilon tensor</p>
<p><strong>metric_symmetry</strong> : integer that denotes metric symmetry or <code class="docutils literal notranslate"><span class="pre">None</span></code> for no metirc</p>
<p><strong>metric_name</strong> : string with the name of the metric tensor</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>The possible values of the <code class="docutils literal notranslate"><span class="pre">metric_symmetry</span></code> parameter are:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">1</span></code>   :   metric tensor is fully symmetric
<code class="docutils literal notranslate"><span class="pre">0</span></code>   :   metric tensor possesses no index symmetry
<code class="docutils literal notranslate"><span class="pre">-1</span></code>  :   metric tensor is fully antisymmetric
<code class="docutils literal notranslate"><span class="pre">None</span></code>:   there is no metric tensor (metric equals to <code class="docutils literal notranslate"><span class="pre">None</span></code>)</p>
</div></blockquote>
<p>The metric is assumed to be symmetric by default. It can also be set
to a custom tensor by the <code class="docutils literal notranslate"><span class="pre">.set_metric()</span></code> method.</p>
<p>If there is a metric the metric is used to raise and lower indices.</p>
<p>In the case of non-symmetric metric, the following raising and
lowering conventions will be adopted:</p>
<p><code class="docutils literal notranslate"><span class="pre">psi(a)</span> <span class="pre">=</span> <span class="pre">g(a,</span> <span class="pre">b)*psi(-b);</span> <span class="pre">chi(-a)</span> <span class="pre">=</span> <span class="pre">chi(b)*g(-b,</span> <span class="pre">-a)</span></code></p>
<p>From these it is easy to find:</p>
<p><code class="docutils literal notranslate"><span class="pre">g(-a,</span> <span class="pre">b)</span> <span class="pre">=</span> <span class="pre">delta(-a,</span> <span class="pre">b)</span></code></p>
<p>where <code class="docutils literal notranslate"><span class="pre">delta(-a,</span> <span class="pre">b)</span> <span class="pre">=</span> <span class="pre">delta(b,</span> <span class="pre">-a)</span></code> is the <code class="docutils literal notranslate"><span class="pre">Kronecker</span> <span class="pre">delta</span></code>
(see <code class="docutils literal notranslate"><span class="pre">TensorIndex</span></code> for the conventions on indices).
For antisymmetric metrics there is also the following equality:</p>
<p><code class="docutils literal notranslate"><span class="pre">g(a,</span> <span class="pre">-b)</span> <span class="pre">=</span> <span class="pre">-delta(a,</span> <span class="pre">-b)</span></code></p>
<p>If there is no metric it is not possible to raise or lower indices;
e.g. the index of the defining representation of <code class="docutils literal notranslate"><span class="pre">SU(N)</span></code>
is ‘covariant’ and the conjugate representation is
‘contravariant’; for <code class="docutils literal notranslate"><span class="pre">N</span> <span class="pre">&gt;</span> <span class="pre">2</span></code> they are linearly independent.</p>
<p><code class="docutils literal notranslate"><span class="pre">eps_dim</span></code> is by default equal to <code class="docutils literal notranslate"><span class="pre">dim</span></code>, if the latter is an integer;
else it can be assigned (for use in naive dimensional regularization);
if <code class="docutils literal notranslate"><span class="pre">eps_dim</span></code> is not an integer <code class="docutils literal notranslate"><span class="pre">epsilon</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span><span class="o">.</span><span class="n">metric</span>
<span class="go">metric(Lorentz,Lorentz)</span>
</pre></div>
</div>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 12%" />
<col style="width: 88%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">metric</span></code></p></td>
<td><p>(the metric tensor)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">delta</span></code></p></td>
<td><p>(<code class="docutils literal notranslate"><span class="pre">Kronecker</span> <span class="pre">delta</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">epsilon</span></code></p></td>
<td><p>(the <code class="docutils literal notranslate"><span class="pre">Levi-Civita</span> <span class="pre">epsilon</span></code> tensor)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">data</span></code></p></td>
<td><p>((deprecated) a property to add <code class="docutils literal notranslate"><span class="pre">ndarray</span></code> values, to work in a specified basis.)</p></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorIndex">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensorIndex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tensor_index_type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">is_up</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1205-L1295"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorIndex" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a tensor index</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>name</strong> : name of the index, or <code class="docutils literal notranslate"><span class="pre">True</span></code> if you want it to be automatically assigned</p>
<p><strong>tensor_index_type</strong> : <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code> of the index</p>
<p><strong>is_up</strong> :  flag for contravariant index (is_up=True by default)</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>Tensor indices are contracted with the Einstein summation convention.</p>
<p>An index can be in contravariant or in covariant form; in the latter
case it is represented prepending a <code class="docutils literal notranslate"><span class="pre">-</span></code> to the index name. Adding
<code class="docutils literal notranslate"><span class="pre">-</span></code> to a covariant (is_up=False) index makes it contravariant.</p>
<p>Dummy indices have a name with head given by
<code class="docutils literal notranslate"><span class="pre">tensor_inde_type.dummy_name</span></code> with underscore and a number.</p>
<p>Similar to <code class="docutils literal notranslate"><span class="pre">symbols</span></code> multiple contravariant indices can be created
at once using <code class="docutils literal notranslate"><span class="pre">tensor_indices(s,</span> <span class="pre">typ)</span></code>, where <code class="docutils literal notranslate"><span class="pre">s</span></code> is a string
of names.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">TensorIndex</span><span class="p">,</span> <span class="n">TensorHead</span><span class="p">,</span> <span class="n">tensor_indices</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mu</span> <span class="o">=</span> <span class="n">TensorIndex</span><span class="p">(</span><span class="s1">&#39;mu&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">,</span> <span class="n">is_up</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nu</span><span class="p">,</span> <span class="n">rho</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;nu, rho&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">(</span><span class="n">mu</span><span class="p">,</span> <span class="n">nu</span><span class="p">)</span>
<span class="go">A(-mu, nu)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">(</span><span class="o">-</span><span class="n">mu</span><span class="p">,</span> <span class="o">-</span><span class="n">rho</span><span class="p">)</span>
<span class="go">A(mu, -rho)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">(</span><span class="n">mu</span><span class="p">,</span> <span class="o">-</span><span class="n">mu</span><span class="p">)</span>
<span class="go">A(-L_0, L_0)</span>
</pre></div>
</div>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 68%" />
<col style="width: 32%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">name</span></code></p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">tensor_index_type</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">is_up</span></code></p></td>
<td></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorHead">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensorHead</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">index_types</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symmetry</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">comm</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1615-L1881"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorHead" title="Permalink to this definition">¶</a></dt>
<dd><p>Tensor head of the tensor.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>name</strong> : name of the tensor</p>
<p><strong>index_types</strong> : list of TensorIndexType</p>
<p><strong>symmetry</strong> : TensorSymmetry of the tensor</p>
<p><strong>comm</strong> : commutation group number</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>Similar to <code class="docutils literal notranslate"><span class="pre">symbols</span></code> multiple TensorHeads can be created using
<code class="docutils literal notranslate"><span class="pre">tensorhead(s,</span> <span class="pre">typ,</span> <span class="pre">sym=None,</span> <span class="pre">comm=0)</span></code> function, where <code class="docutils literal notranslate"><span class="pre">s</span></code>
is the string of names and <code class="docutils literal notranslate"><span class="pre">sym</span></code> is the monoterm tensor symmetry
(see <code class="docutils literal notranslate"><span class="pre">tensorsymmetry</span></code>).</p>
<p>A <code class="docutils literal notranslate"><span class="pre">TensorHead</span></code> belongs to a commutation group, defined by a
symbol on number <code class="docutils literal notranslate"><span class="pre">comm</span></code> (see <code class="docutils literal notranslate"><span class="pre">_TensorManager.set_comm</span></code>);
tensors in a commutation group have the same commutation properties;
by default <code class="docutils literal notranslate"><span class="pre">comm</span></code> is <code class="docutils literal notranslate"><span class="pre">0</span></code>, the group of the commuting tensors.</p>
<p class="rubric">Examples</p>
<p>Define a fully antisymmetric tensor of rank 2:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">TensorHead</span><span class="p">,</span> <span class="n">TensorSymmetry</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">asym2</span> <span class="o">=</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">fully_symmetric</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">],</span> <span class="n">asym2</span><span class="p">)</span>
</pre></div>
</div>
<p>Examples with ndarray values, the components data assigned to the
<code class="docutils literal notranslate"><span class="pre">TensorHead</span></code> object are assumed to be in a fully-contravariant
representation. In case it is necessary to assign components data which
represents the values of a non-fully covariant tensor, see the other
examples.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">tensor_indices</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">diag</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i0</span><span class="p">,</span> <span class="n">i1</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;i0:2&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
</pre></div>
</div>
<p>Specify a replacement dictionary to keep track of the arrays to use for
replacements in the tensorial expression. The <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code> is
associated to the metric used for contractions (in fully covariant form):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span> <span class="o">=</span> <span class="p">{</span><span class="n">Lorentz</span><span class="p">:</span> <span class="n">diag</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)}</span>
</pre></div>
</div>
<p>Let’s see some examples of working with components with the electromagnetic
tensor:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Ex</span><span class="p">,</span> <span class="n">Ey</span><span class="p">,</span> <span class="n">Ez</span><span class="p">,</span> <span class="n">Bx</span><span class="p">,</span> <span class="n">By</span><span class="p">,</span> <span class="n">Bz</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;E_x E_y E_z B_x B_y B_z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Let’s define <span class="math notranslate nohighlight">\(F\)</span>, an antisymmetric tensor:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">],</span> <span class="n">asym2</span><span class="p">)</span>
</pre></div>
</div>
<p>Let’s update the dictionary to contain the matrix to use in the
replacements:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">F</span><span class="p">(</span><span class="o">-</span><span class="n">i0</span><span class="p">,</span> <span class="o">-</span><span class="n">i1</span><span class="p">):</span> <span class="p">[</span>
<span class="gp">... </span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">Ex</span><span class="o">/</span><span class="n">c</span><span class="p">,</span> <span class="n">Ey</span><span class="o">/</span><span class="n">c</span><span class="p">,</span> <span class="n">Ez</span><span class="o">/</span><span class="n">c</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span><span class="o">-</span><span class="n">Ex</span><span class="o">/</span><span class="n">c</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="n">Bz</span><span class="p">,</span> <span class="n">By</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span><span class="o">-</span><span class="n">Ey</span><span class="o">/</span><span class="n">c</span><span class="p">,</span> <span class="n">Bz</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="n">Bx</span><span class="p">],</span>
<span class="gp">... </span><span class="p">[</span><span class="o">-</span><span class="n">Ez</span><span class="o">/</span><span class="n">c</span><span class="p">,</span> <span class="o">-</span><span class="n">By</span><span class="p">,</span> <span class="n">Bx</span><span class="p">,</span> <span class="mi">0</span><span class="p">]]})</span>
</pre></div>
</div>
<p>Now it is possible to retrieve the contravariant form of the Electromagnetic
tensor:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">F</span><span class="p">(</span><span class="n">i0</span><span class="p">,</span> <span class="n">i1</span><span class="p">)</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">,</span> <span class="p">[</span><span class="n">i0</span><span class="p">,</span> <span class="n">i1</span><span class="p">])</span>
<span class="go">[[0, -E_x/c, -E_y/c, -E_z/c], [E_x/c, 0, -B_z, B_y], [E_y/c, B_z, 0, -B_x], [E_z/c, -B_y, B_x, 0]]</span>
</pre></div>
</div>
<p>and the mixed contravariant-covariant form:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">F</span><span class="p">(</span><span class="n">i0</span><span class="p">,</span> <span class="o">-</span><span class="n">i1</span><span class="p">)</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">,</span> <span class="p">[</span><span class="n">i0</span><span class="p">,</span> <span class="o">-</span><span class="n">i1</span><span class="p">])</span>
<span class="go">[[0, E_x/c, E_y/c, E_z/c], [E_x/c, 0, B_z, -B_y], [E_y/c, -B_z, 0, B_x], [E_z/c, B_y, -B_x, 0]]</span>
</pre></div>
</div>
<p>Energy-momentum of a particle may be represented as:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;P&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">],</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">no_symmetry</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">E</span><span class="p">,</span> <span class="n">px</span><span class="p">,</span> <span class="n">py</span><span class="p">,</span> <span class="n">pz</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;E p_x p_y p_z&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">P</span><span class="p">(</span><span class="n">i0</span><span class="p">):</span> <span class="p">[</span><span class="n">E</span><span class="p">,</span> <span class="n">px</span><span class="p">,</span> <span class="n">py</span><span class="p">,</span> <span class="n">pz</span><span class="p">]})</span>
</pre></div>
</div>
<p>The contravariant and covariant components are, respectively:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="n">i0</span><span class="p">)</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">,</span> <span class="p">[</span><span class="n">i0</span><span class="p">])</span>
<span class="go">[E, p_x, p_y, p_z]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">P</span><span class="p">(</span><span class="o">-</span><span class="n">i0</span><span class="p">)</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="n">i0</span><span class="p">])</span>
<span class="go">[E, -p_x, -p_y, -p_z]</span>
</pre></div>
</div>
<p>The contraction of a 1-index tensor by itself:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">P</span><span class="p">(</span><span class="n">i0</span><span class="p">)</span><span class="o">*</span><span class="n">P</span><span class="p">(</span><span class="o">-</span><span class="n">i0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">,</span> <span class="p">[])</span>
<span class="go">E**2 - p_x**2 - p_y**2 - p_z**2</span>
</pre></div>
</div>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 38%" />
<col style="width: 63%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">name</span></code></p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">index_types</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">rank</span></code></p></td>
<td><p>(total number of indices)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">symmetry</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">comm</span></code></p></td>
<td><p>(commutation group)</p></td>
</tr>
</tbody>
</table>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorHead.commutes_with">
<span class="sig-name descname"><span class="pre">commutes_with</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1765-L1772"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorHead.commutes_with" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> if <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">other</span></code> commute, <code class="docutils literal notranslate"><span class="pre">1</span></code> if they anticommute.</p>
<p>Returns <code class="docutils literal notranslate"><span class="pre">None</span></code> if <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">other</span></code> neither commute nor anticommute.</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensExpr">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensExpr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1903-L2309"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensExpr" title="Permalink to this definition">¶</a></dt>
<dd><p>Abstract base class for tensor expressions</p>
<p class="rubric">Notes</p>
<p>A tensor expression is an expression formed by tensors;
currently the sums of tensors are distributed.</p>
<p>A <code class="docutils literal notranslate"><span class="pre">TensExpr</span></code> can be a <code class="docutils literal notranslate"><span class="pre">TensAdd</span></code> or a <code class="docutils literal notranslate"><span class="pre">TensMul</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">TensMul</span></code> objects are formed by products of component tensors,
and include a coefficient, which is a SymPy expression.</p>
<p>In the internal representation contracted indices are represented
by <code class="docutils literal notranslate"><span class="pre">(ipos1,</span> <span class="pre">ipos2,</span> <span class="pre">icomp1,</span> <span class="pre">icomp2)</span></code>, where <code class="docutils literal notranslate"><span class="pre">icomp1</span></code> is the position
of the component tensor with contravariant index, <code class="docutils literal notranslate"><span class="pre">ipos1</span></code> is the
slot which the index occupies in that component tensor.</p>
<p>Contracted indices are therefore nameless in the internal representation.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensExpr.get_matrix">
<span class="sig-name descname"><span class="pre">get_matrix</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L2034-L2059"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensExpr.get_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>DEPRECATED: do not use.</p>
<p>Returns ndarray components data as a matrix, if components data are
available and ndarray dimension does not exceed 2.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensExpr.replace_with_arrays">
<span class="sig-name descname"><span class="pre">replace_with_arrays</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">replacement_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">indices</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L2204-L2291"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensExpr.replace_with_arrays" title="Permalink to this definition">¶</a></dt>
<dd><p>Replace the tensorial expressions with arrays. The final array will
correspond to the N-dimensional array with indices arranged according
to <code class="docutils literal notranslate"><span class="pre">indices</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>replacement_dict</strong></p>
<blockquote>
<div><p>dictionary containing the replacement rules for tensors.</p>
</div></blockquote>
<p><strong>indices</strong></p>
<blockquote>
<div><p>the index order with respect to which the array is read. The
original index order will be used if no value is passed.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorHead</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">diag</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s2">&quot;L&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s2">&quot;i j&quot;</span><span class="p">,</span> <span class="n">L</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s2">&quot;A&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">L</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">({</span><span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">):</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]},</span> <span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="go">[1, 2]</span>
</pre></div>
</div>
<p>Since ‘indices’ is optional, we can also call replace_with_arrays by
this way if no specific index order is needed:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">({</span><span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">):</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]})</span>
<span class="go">[1, 2]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">*</span><span class="n">A</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">({</span><span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">):</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]})</span>
<span class="go">[[1, 2], [2, 4]]</span>
</pre></div>
</div>
<p>For contractions, specify the metric of the <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code>, which
in this case is <code class="docutils literal notranslate"><span class="pre">L</span></code>, in its covariant form:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">*</span><span class="n">A</span><span class="p">(</span><span class="o">-</span><span class="n">i</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">({</span><span class="n">A</span><span class="p">(</span><span class="n">i</span><span class="p">):</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">L</span><span class="p">:</span> <span class="n">diag</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)})</span>
<span class="go">-3</span>
</pre></div>
</div>
<p>Symmetrization of an array:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">H</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s2">&quot;H&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">L</span><span class="p">,</span> <span class="n">L</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;a b c d&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">H</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="n">H</span><span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">({</span><span class="n">H</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">):</span> <span class="p">[[</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">],</span> <span class="p">[</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">]]})</span>
<span class="go">[[a, b/2 + c/2], [b/2 + c/2, d]]</span>
</pre></div>
</div>
<p>Anti-symmetrization of an array:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">H</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span> <span class="o">-</span> <span class="n">H</span><span class="p">(</span><span class="n">j</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span> <span class="o">=</span> <span class="p">{</span><span class="n">H</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">):</span> <span class="p">[[</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">],</span> <span class="p">[</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">]]}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">)</span>
<span class="go">[[0, b/2 - c/2], [-b/2 + c/2, 0]]</span>
</pre></div>
</div>
<p>The same expression can be read as the transpose by inverting <code class="docutils literal notranslate"><span class="pre">i</span></code> and
<code class="docutils literal notranslate"><span class="pre">j</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">,</span> <span class="p">[</span><span class="n">j</span><span class="p">,</span> <span class="n">i</span><span class="p">])</span>
<span class="go">[[0, -b/2 + c/2], [b/2 - c/2, 0]]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensAdd">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensAdd</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw_args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L2312-L2659"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensAdd" title="Permalink to this definition">¶</a></dt>
<dd><p>Sum of tensors.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>free_args</strong> : list of the free indices</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_heads</span><span class="p">,</span> <span class="n">tensor_indices</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;a,b&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">,</span> <span class="n">q</span> <span class="o">=</span> <span class="n">tensor_heads</span><span class="p">(</span><span class="s1">&#39;p,q&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">p</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">+</span> <span class="n">q</span><span class="p">(</span><span class="n">a</span><span class="p">);</span> <span class="n">t</span>
<span class="go">p(a) + q(a)</span>
</pre></div>
</div>
<p>Examples with components data added to the tensor expression:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">diag</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">t</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x y z t&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span> <span class="o">=</span> <span class="p">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span><span class="p">[</span><span class="n">Lorentz</span><span class="p">]</span> <span class="o">=</span> <span class="n">diag</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span><span class="p">[</span><span class="n">p</span><span class="p">(</span><span class="n">a</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">repl</span><span class="p">[</span><span class="n">q</span><span class="p">(</span><span class="n">a</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">t</span><span class="p">]</span>
</pre></div>
</div>
<p>The following are: 2**2 - 3**2 - 2**2 - 7**2 ==&gt; -58</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">p</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">+</span> <span class="n">q</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span><span class="o">.</span><span class="n">replace_with_arrays</span><span class="p">(</span><span class="n">repl</span><span class="p">,</span> <span class="p">[</span><span class="n">a</span><span class="p">])</span>
<span class="go">[x + 1, y + 2, z + 3, t + 4]</span>
</pre></div>
</div>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 24%" />
<col style="width: 76%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">args</span></code></p></td>
<td><p>(tuple of addends)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">rank</span></code></p></td>
<td><p>(rank of the tensor)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">free_args</span></code></p></td>
<td><p>(list of the free indices in sorted order)</p></td>
</tr>
</tbody>
</table>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensAdd.canon_bp">
<span class="sig-name descname"><span class="pre">canon_bp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L2531-L2539"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensAdd.canon_bp" title="Permalink to this definition">¶</a></dt>
<dd><p>Canonicalize using the Butler-Portugal algorithm for canonicalization
under monoterm symmetries.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensAdd.contract_metric">
<span class="sig-name descname"><span class="pre">contract_metric</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">g</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L2571-L2590"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensAdd.contract_metric" title="Permalink to this definition">¶</a></dt>
<dd><p>Raise or lower indices with the metric <code class="docutils literal notranslate"><span class="pre">g</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>g</strong> :  metric</p>
<p><strong>contract_all</strong> : if True, eliminate all <code class="docutils literal notranslate"><span class="pre">g</span></code> which are contracted</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>see the <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code> docstring for the contraction conventions</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensMul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw_args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3124-L3925"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul" title="Permalink to this definition">¶</a></dt>
<dd><p>Product of tensors.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>coeff</strong> : SymPy coefficient of the tensor</p>
<p><strong>args</strong></p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p><code class="docutils literal notranslate"><span class="pre">args[0]</span></code>   list of <code class="docutils literal notranslate"><span class="pre">TensorHead</span></code> of the component tensors.</p>
<p><code class="docutils literal notranslate"><span class="pre">args[1]</span></code>   list of <code class="docutils literal notranslate"><span class="pre">(ind,</span> <span class="pre">ipos,</span> <span class="pre">icomp)</span></code>
where <code class="docutils literal notranslate"><span class="pre">ind</span></code> is a free index, <code class="docutils literal notranslate"><span class="pre">ipos</span></code> is the slot position
of <code class="docutils literal notranslate"><span class="pre">ind</span></code> in the <code class="docutils literal notranslate"><span class="pre">icomp</span></code>-th component tensor.</p>
<p><code class="docutils literal notranslate"><span class="pre">args[2]</span></code> list of tuples representing dummy indices.
<code class="docutils literal notranslate"><span class="pre">(ipos1,</span> <span class="pre">ipos2,</span> <span class="pre">icomp1,</span> <span class="pre">icomp2)</span></code> indicates that the contravariant
dummy index is the <code class="docutils literal notranslate"><span class="pre">ipos1</span></code>-th slot position in the <code class="docutils literal notranslate"><span class="pre">icomp1</span></code>-th
component tensor; the corresponding covariant index is
in the <code class="docutils literal notranslate"><span class="pre">ipos2</span></code> slot position in the <code class="docutils literal notranslate"><span class="pre">icomp2</span></code>-th component tensor.</p>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 21%" />
<col style="width: 79%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">components</span></code></p></td>
<td><p>(list of <code class="docutils literal notranslate"><span class="pre">TensorHead</span></code> of the component tensors)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">types</span></code></p></td>
<td><p>(list of nonrepeated <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code>)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">free</span></code></p></td>
<td><p>(list of <code class="docutils literal notranslate"><span class="pre">(ind,</span> <span class="pre">ipos,</span> <span class="pre">icomp)</span></code>, see Notes)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">dum</span></code></p></td>
<td><p>(list of <code class="docutils literal notranslate"><span class="pre">(ipos1,</span> <span class="pre">ipos2,</span> <span class="pre">icomp1,</span> <span class="pre">icomp2)</span></code>, see Notes)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ext_rank</span></code></p></td>
<td><p>(rank of the tensor counting the dummy indices)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">rank</span></code></p></td>
<td><p>(rank of the tensor)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">coeff</span></code></p></td>
<td><p>(SymPy coefficient of the tensor)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">free_args</span></code></p></td>
<td><p>(list of the free indices in sorted order)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">is_canon_bp</span></code></p></td>
<td><p>(<code class="docutils literal notranslate"><span class="pre">True</span></code> if the tensor in in canonical form)</p></td>
</tr>
</tbody>
</table>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul.canon_bp">
<span class="sig-name descname"><span class="pre">canon_bp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3603-L3636"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul.canon_bp" title="Permalink to this definition">¶</a></dt>
<dd><p>Canonicalize using the Butler-Portugal algorithm for canonicalization
under monoterm symmetries.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span><span class="p">,</span> <span class="n">TensorHead</span><span class="p">,</span> <span class="n">TensorSymmetry</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m0</span><span class="p">,</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;m0,m1,m2&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">,</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">fully_symmetric</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">A</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span><span class="o">-</span><span class="n">m1</span><span class="p">)</span><span class="o">*</span><span class="n">A</span><span class="p">(</span><span class="n">m1</span><span class="p">,</span><span class="o">-</span><span class="n">m0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">canon_bp</span><span class="p">()</span>
<span class="go">-A(L_0, L_1)*A(-L_0, -L_1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">A</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span><span class="o">-</span><span class="n">m1</span><span class="p">)</span><span class="o">*</span><span class="n">A</span><span class="p">(</span><span class="n">m1</span><span class="p">,</span><span class="o">-</span><span class="n">m2</span><span class="p">)</span><span class="o">*</span><span class="n">A</span><span class="p">(</span><span class="n">m2</span><span class="p">,</span><span class="o">-</span><span class="n">m0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">canon_bp</span><span class="p">()</span>
<span class="go">0</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul.contract_metric">
<span class="sig-name descname"><span class="pre">contract_metric</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">g</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3657-L3819"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul.contract_metric" title="Permalink to this definition">¶</a></dt>
<dd><p>Raise or lower indices with the metric <code class="docutils literal notranslate"><span class="pre">g</span></code>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>g</strong> : metric</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>See the <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code> docstring for the contraction conventions.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span><span class="p">,</span> <span class="n">tensor_heads</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m0</span><span class="p">,</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;m0,m1,m2&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">Lorentz</span><span class="o">.</span><span class="n">metric</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">,</span> <span class="n">q</span> <span class="o">=</span> <span class="n">tensor_heads</span><span class="p">(</span><span class="s1">&#39;p,q&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">p</span><span class="p">(</span><span class="n">m0</span><span class="p">)</span><span class="o">*</span><span class="n">q</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span><span class="o">*</span><span class="n">g</span><span class="p">(</span><span class="o">-</span><span class="n">m0</span><span class="p">,</span> <span class="o">-</span><span class="n">m1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">canon_bp</span><span class="p">()</span>
<span class="go">metric(L_0, L_1)*p(-L_0)*q(-L_1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">contract_metric</span><span class="p">(</span><span class="n">g</span><span class="p">)</span><span class="o">.</span><span class="n">canon_bp</span><span class="p">()</span>
<span class="go">p(L_0)*q(-L_0)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul.get_free_indices">
<span class="sig-name descname"><span class="pre">get_free_indices</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">List</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#sympy.tensor.tensor.TensorIndex" title="sympy.tensor.tensor.TensorIndex"><span class="pre">sympy.tensor.tensor.TensorIndex</span></a><span class="p"><span class="pre">]</span></span></span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3461-L3486"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul.get_free_indices" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of free indices of the tensor.</p>
<p class="rubric">Explanation</p>
<p>The indices are listed in the order in which they appear in the
component tensors.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span><span class="p">,</span> <span class="n">tensor_heads</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m0</span><span class="p">,</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;m0,m1,m2&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">Lorentz</span><span class="o">.</span><span class="n">metric</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">,</span> <span class="n">q</span> <span class="o">=</span> <span class="n">tensor_heads</span><span class="p">(</span><span class="s1">&#39;p,q&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">p</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span><span class="o">*</span><span class="n">g</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span><span class="n">m2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">get_free_indices</span><span class="p">()</span>
<span class="go">[m1, m0, m2]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t2</span> <span class="o">=</span> <span class="n">p</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span><span class="o">*</span><span class="n">g</span><span class="p">(</span><span class="o">-</span><span class="n">m1</span><span class="p">,</span> <span class="n">m2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t2</span><span class="o">.</span><span class="n">get_free_indices</span><span class="p">()</span>
<span class="go">[m2]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul.get_indices">
<span class="sig-name descname"><span class="pre">get_indices</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3432-L3459"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul.get_indices" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the list of indices of the tensor.</p>
<p class="rubric">Explanation</p>
<p>The indices are listed in the order in which they appear in the
component tensors.
The dummy indices are given a name which does not collide with
the names of the free indices.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span><span class="p">,</span> <span class="n">tensor_heads</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m0</span><span class="p">,</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;m0,m1,m2&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">Lorentz</span><span class="o">.</span><span class="n">metric</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">,</span> <span class="n">q</span> <span class="o">=</span> <span class="n">tensor_heads</span><span class="p">(</span><span class="s1">&#39;p,q&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">p</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span><span class="o">*</span><span class="n">g</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span><span class="n">m2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">get_indices</span><span class="p">()</span>
<span class="go">[m1, m0, m2]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t2</span> <span class="o">=</span> <span class="n">p</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span><span class="o">*</span><span class="n">g</span><span class="p">(</span><span class="o">-</span><span class="n">m1</span><span class="p">,</span> <span class="n">m2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t2</span><span class="o">.</span><span class="n">get_indices</span><span class="p">()</span>
<span class="go">[L_0, -L_0, m2]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul.perm2tensor">
<span class="sig-name descname"><span class="pre">perm2tensor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">g</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">is_canon_bp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3595-L3601"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul.perm2tensor" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the tensor corresponding to the permutation <code class="docutils literal notranslate"><span class="pre">g</span></code></p>
<p>For further details, see the method in <code class="docutils literal notranslate"><span class="pre">TIDS</span></code> with the same name.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul.sorted_components">
<span class="sig-name descname"><span class="pre">sorted_components</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3589-L3593"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul.sorted_components" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a tensor product with sorted components.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensMul.split">
<span class="sig-name descname"><span class="pre">split</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L3491-L3525"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensMul.split" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of tensors, whose product is <code class="docutils literal notranslate"><span class="pre">self</span></code>.</p>
<p class="rubric">Explanation</p>
<p>Dummy indices contracted among different tensor components
become free indices with the same name as the one used to
represent the dummy indices.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span><span class="p">,</span> <span class="n">tensor_heads</span><span class="p">,</span> <span class="n">TensorSymmetry</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;a,b,c,d&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="n">tensor_heads</span><span class="p">(</span><span class="s1">&#39;A,B&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">,</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">fully_symmetric</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">A</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span><span class="o">*</span><span class="n">B</span><span class="p">(</span><span class="o">-</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span>
<span class="go">A(a, L_0)*B(-L_0, c)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
<span class="go">[A(a, L_0), B(-L_0, c)]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.tensor.tensor.canon_bp">
<span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">canon_bp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">p</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L4018-L4025"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.canon_bp" title="Permalink to this definition">¶</a></dt>
<dd><p>Butler-Portugal canonicalization. See <code class="docutils literal notranslate"><span class="pre">tensor_can.py</span></code> from the
combinatorics module for the details.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.tensor.tensor.riemann_cyclic_replace">
<span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">riemann_cyclic_replace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">t_r</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L4040-L4053"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.riemann_cyclic_replace" title="Permalink to this definition">¶</a></dt>
<dd><p>replace Riemann tensor with an equivalent expression</p>
<p><code class="docutils literal notranslate"><span class="pre">R(m,n,p,q)</span> <span class="pre">-&gt;</span> <span class="pre">2/3*R(m,n,p,q)</span> <span class="pre">-</span> <span class="pre">1/3*R(m,q,n,p)</span> <span class="pre">+</span> <span class="pre">1/3*R(m,p,n,q)</span></code></p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.tensor.tensor.riemann_cyclic">
<span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">riemann_cyclic</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">t2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L4055-L4085"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.riemann_cyclic" title="Permalink to this definition">¶</a></dt>
<dd><p>Replace each Riemann tensor with an equivalent expression
satisfying the cyclic identity.</p>
<p>This trick is discussed in the reference guide to Cadabra.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span><span class="p">,</span> <span class="n">TensorHead</span><span class="p">,</span> <span class="n">riemann_cyclic</span><span class="p">,</span> <span class="n">TensorSymmetry</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;i,j,k,l&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">R</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">]</span><span class="o">*</span><span class="mi">4</span><span class="p">,</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">riemann</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">R</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">l</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">R</span><span class="p">(</span><span class="o">-</span><span class="n">i</span><span class="p">,</span><span class="o">-</span><span class="n">j</span><span class="p">,</span><span class="o">-</span><span class="n">k</span><span class="p">,</span><span class="o">-</span><span class="n">l</span><span class="p">)</span> <span class="o">-</span> <span class="mi">2</span><span class="o">*</span><span class="n">R</span><span class="p">(</span><span class="o">-</span><span class="n">i</span><span class="p">,</span><span class="o">-</span><span class="n">k</span><span class="p">,</span><span class="o">-</span><span class="n">j</span><span class="p">,</span><span class="o">-</span><span class="n">l</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">riemann_cyclic</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorSymmetry">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensorSymmetry</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw_args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1327-L1456"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorSymmetry" title="Permalink to this definition">¶</a></dt>
<dd><p>Monoterm symmetry of a tensor (i.e. any symmetric or anti-symmetric
index permutation). For the relevant terminology see <code class="docutils literal notranslate"><span class="pre">tensor_can.py</span></code>
section of the combinatorics module.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>bsgs</strong> : tuple <code class="docutils literal notranslate"><span class="pre">(base,</span> <span class="pre">sgs)</span></code> BSGS of the symmetry of the tensor</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>A tensor can have an arbitrary monoterm symmetry provided by its BSGS.
Multiterm symmetries, like the cyclic symmetry of the Riemann tensor
(i.e., Bianchi identity), are not covered. See combinatorics module for
information on how to generate BSGS for a general index permutation group.
Simple symmetries can be generated using built-in methods.</p>
<p class="rubric">Examples</p>
<p>Define a symmetric tensor of rank 2</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">TensorSymmetry</span><span class="p">,</span> <span class="n">get_symmetric_group_sgs</span><span class="p">,</span> <span class="n">TensorHead</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">,</span> <span class="n">dummy_name</span><span class="o">=</span><span class="s1">&#39;L&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sym</span> <span class="o">=</span> <span class="n">TensorSymmetry</span><span class="p">(</span><span class="n">get_symmetric_group_sgs</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">T</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;T&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">,</span> <span class="n">sym</span><span class="p">)</span>
</pre></div>
</div>
<p>Note, that the same can also be done using built-in TensorSymmetry methods</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sym2</span> <span class="o">=</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">fully_symmetric</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sym</span> <span class="o">==</span> <span class="n">sym2</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../combinatorics/tensor_can.html#sympy.combinatorics.tensor_can.get_symmetric_group_sgs" title="sympy.combinatorics.tensor_can.get_symmetric_group_sgs"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.combinatorics.tensor_can.get_symmetric_group_sgs</span></code></a></p>
</div>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 37%" />
<col style="width: 63%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">base</span></code></p></td>
<td><p>(base of the BSGS)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">generators</span></code></p></td>
<td><p>(generators of the BSGS)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">rank</span></code></p></td>
<td><p>(rank of the tensor)</p></td>
</tr>
</tbody>
</table>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorSymmetry.direct_product">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">direct_product</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1416-L1442"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorSymmetry.direct_product" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a TensorSymmetry object that is being a direct product of
fully (anti-)symmetric index permutation groups.</p>
<p class="rubric">Notes</p>
<p>Some examples for different values of <code class="docutils literal notranslate"><span class="pre">(*args)</span></code>:
<code class="docutils literal notranslate"><span class="pre">(1)</span></code>         vector, equivalent to <code class="docutils literal notranslate"><span class="pre">TensorSymmetry.fully_symmetric(1)</span></code>
<code class="docutils literal notranslate"><span class="pre">(2)</span></code>         tensor with 2 symmetric indices, equivalent to <code class="docutils literal notranslate"><span class="pre">.fully_symmetric(2)</span></code>
<code class="docutils literal notranslate"><span class="pre">(-2)</span></code>        tensor with 2 antisymmetric indices, equivalent to <code class="docutils literal notranslate"><span class="pre">.fully_symmetric(-2)</span></code>
<code class="docutils literal notranslate"><span class="pre">(2,</span> <span class="pre">-2)</span></code>     tensor with the first 2 indices commuting and the last 2 anticommuting
<code class="docutils literal notranslate"><span class="pre">(1,</span> <span class="pre">1,</span> <span class="pre">1)</span></code>   tensor with 3 indices without any symmetry</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorSymmetry.fully_symmetric">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">fully_symmetric</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rank</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1402-L1414"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorSymmetry.fully_symmetric" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a fully symmetric (antisymmetric if <code class="docutils literal notranslate"><span class="pre">rank``&lt;0)</span>
<span class="pre">TensorSymmetry</span> <span class="pre">object</span> <span class="pre">for</span> <span class="pre">``abs(rank)</span></code> indices.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorSymmetry.no_symmetry">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">no_symmetry</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rank</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1451-L1456"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorSymmetry.no_symmetry" title="Permalink to this definition">¶</a></dt>
<dd><p>TensorSymmetry object for <code class="docutils literal notranslate"><span class="pre">rank</span></code> indices with no symmetry</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorSymmetry.riemann">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">riemann</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1444-L1449"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorSymmetry.riemann" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a monotorem symmetry of the Riemann tensor</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.tensor.tensor.tensorsymmetry">
<span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">tensorsymmetry</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1459-L1524"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.tensorsymmetry" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <code class="docutils literal notranslate"><span class="pre">TensorSymmetry</span></code> object. This method is deprecated, use
<code class="docutils literal notranslate"><span class="pre">TensorSymmetry.direct_product()</span></code> or <code class="docutils literal notranslate"><span class="pre">.riemann()</span></code> instead.</p>
<p class="rubric">Explanation</p>
<p>One can represent a tensor with any monoterm slot symmetry group
using a BSGS.</p>
<p><code class="docutils literal notranslate"><span class="pre">args</span></code> can be a BSGS
<code class="docutils literal notranslate"><span class="pre">args[0]</span></code>    base
<code class="docutils literal notranslate"><span class="pre">args[1]</span></code>    sgs</p>
<p>Usually tensors are in (direct products of) representations
of the symmetric group;
<code class="docutils literal notranslate"><span class="pre">args</span></code> can be a list of lists representing the shapes of Young tableaux</p>
<p class="rubric">Notes</p>
<p>For instance:
<code class="docutils literal notranslate"><span class="pre">[[1]]</span></code>       vector
<code class="docutils literal notranslate"><span class="pre">[[1]*n]</span></code>     symmetric tensor of rank <code class="docutils literal notranslate"><span class="pre">n</span></code>
<code class="docutils literal notranslate"><span class="pre">[[n]]</span></code>       antisymmetric tensor of rank <code class="docutils literal notranslate"><span class="pre">n</span></code>
<code class="docutils literal notranslate"><span class="pre">[[2,</span> <span class="pre">2]]</span></code>    monoterm slot symmetry of the Riemann tensor
<code class="docutils literal notranslate"><span class="pre">[[1],[1]]</span></code>   vector*vector
<code class="docutils literal notranslate"><span class="pre">[[2],[1],[1]</span></code> (antisymmetric tensor)*vector*vector</p>
<p>Notice that with the shape <code class="docutils literal notranslate"><span class="pre">[2,</span> <span class="pre">2]</span></code> we associate only the monoterm
symmetries of the Riemann tensor; this is an abuse of notation,
since the shape <code class="docutils literal notranslate"><span class="pre">[2,</span> <span class="pre">2]</span></code> corresponds usually to the irreducible
representation characterized by the monoterm symmetries and by the
cyclic symmetry.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor.TensorType">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">TensorType</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">index_types</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symmetry</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw_args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L1527-L1587"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor.TensorType" title="Permalink to this definition">¶</a></dt>
<dd><p>Class of tensor types. Deprecated, use tensor_heads() instead.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>index_types</strong> : list of <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code> of the tensor indices</p>
<p><strong>symmetry</strong> : <code class="docutils literal notranslate"><span class="pre">TensorSymmetry</span></code> of the tensor</p>
</dd>
</dl>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 23%" />
<col style="width: 77%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">index_types</span></code></p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">symmetry</span></code></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">types</span></code></p></td>
<td><p>(list of <code class="docutils literal notranslate"><span class="pre">TensorIndexType</span></code> without repetitions)</p></td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.tensor.tensor._TensorManager">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.tensor.tensor.</span></span><span class="sig-name descname"><span class="pre">_TensorManager</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L766-L925"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor._TensorManager" title="Permalink to this definition">¶</a></dt>
<dd><p>Class to manage tensor properties.</p>
<p class="rubric">Notes</p>
<p>Tensors belong to tensor commutation groups; each group has a label
<code class="docutils literal notranslate"><span class="pre">comm</span></code>; there are predefined labels:</p>
<p><code class="docutils literal notranslate"><span class="pre">0</span></code>   tensors commuting with any other tensor</p>
<p><code class="docutils literal notranslate"><span class="pre">1</span></code>   tensors anticommuting among themselves</p>
<p><code class="docutils literal notranslate"><span class="pre">2</span></code>   tensors not commuting, apart with those with <code class="docutils literal notranslate"><span class="pre">comm=0</span></code></p>
<p>Other groups can be defined using <code class="docutils literal notranslate"><span class="pre">set_comm</span></code>; tensors in those
groups commute with those with <code class="docutils literal notranslate"><span class="pre">comm=0</span></code>; by default they
do not commute with any other group.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor._TensorManager.clear">
<span class="sig-name descname"><span class="pre">clear</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L921-L925"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor._TensorManager.clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clear the TensorManager.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor._TensorManager.comm_i2symbol">
<span class="sig-name descname"><span class="pre">comm_i2symbol</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L823-L827"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor._TensorManager.comm_i2symbol" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the symbol corresponding to the commutation group number.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor._TensorManager.comm_symbols2i">
<span class="sig-name descname"><span class="pre">comm_symbols2i</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L804-L821"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor._TensorManager.comm_symbols2i" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the commutation group number corresponding to <code class="docutils literal notranslate"><span class="pre">i</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">i</span></code> can be a symbol or a number or a string.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">i</span></code> is not already defined its commutation group number
is set.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor._TensorManager.get_comm">
<span class="sig-name descname"><span class="pre">get_comm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">j</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L913-L919"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor._TensorManager.get_comm" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the commutation parameter for commutation group numbers <code class="docutils literal notranslate"><span class="pre">i,</span> <span class="pre">j</span></code></p>
<p>see <code class="docutils literal notranslate"><span class="pre">_TensorManager.set_comm</span></code></p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor._TensorManager.set_comm">
<span class="sig-name descname"><span class="pre">set_comm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">j</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L829-L899"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor._TensorManager.set_comm" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the commutation parameter <code class="docutils literal notranslate"><span class="pre">c</span></code> for commutation groups <code class="docutils literal notranslate"><span class="pre">i,</span> <span class="pre">j</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>i, j</strong> : symbols representing commutation groups</p>
<p><strong>c</strong> :  group commutation number</p>
</dd>
</dl>
<p class="rubric">Notes</p>
<p><code class="docutils literal notranslate"><span class="pre">i,</span> <span class="pre">j</span></code> can be symbols, strings or numbers,
apart from <code class="docutils literal notranslate"><span class="pre">0,</span> <span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">2</span></code> which are reserved respectively
for commuting, anticommuting tensors and tensors not commuting
with any other group apart with the commuting tensors.
For the remaining cases, use this method to set the commutation rules;
by default <code class="docutils literal notranslate"><span class="pre">c=None</span></code>.</p>
<p>The group commutation number <code class="docutils literal notranslate"><span class="pre">c</span></code> is assigned in correspondence
to the group commutation symbols; it can be</p>
<p>0        commuting</p>
<p>1        anticommuting</p>
<p>None     no commutation property</p>
<p class="rubric">Examples</p>
<p><code class="docutils literal notranslate"><span class="pre">G</span></code> and <code class="docutils literal notranslate"><span class="pre">GH</span></code> do not commute with themselves and commute with
each other; A is commuting.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.tensor.tensor</span> <span class="kn">import</span> <span class="n">TensorIndexType</span><span class="p">,</span> <span class="n">tensor_indices</span><span class="p">,</span> <span class="n">TensorHead</span><span class="p">,</span> <span class="n">TensorManager</span><span class="p">,</span> <span class="n">TensorSymmetry</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Lorentz</span> <span class="o">=</span> <span class="n">TensorIndexType</span><span class="p">(</span><span class="s1">&#39;Lorentz&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i0</span><span class="p">,</span><span class="n">i1</span><span class="p">,</span><span class="n">i2</span><span class="p">,</span><span class="n">i3</span><span class="p">,</span><span class="n">i4</span> <span class="o">=</span> <span class="n">tensor_indices</span><span class="p">(</span><span class="s1">&#39;i0:5&#39;</span><span class="p">,</span> <span class="n">Lorentz</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;G&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">],</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">no_symmetry</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="s1">&#39;Gcomm&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">GH</span> <span class="o">=</span> <span class="n">TensorHead</span><span class="p">(</span><span class="s1">&#39;GH&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Lorentz</span><span class="p">],</span> <span class="n">TensorSymmetry</span><span class="o">.</span><span class="n">no_symmetry</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="s1">&#39;GHcomm&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">TensorManager</span><span class="o">.</span><span class="n">set_comm</span><span class="p">(</span><span class="s1">&#39;Gcomm&#39;</span><span class="p">,</span> <span class="s1">&#39;GHcomm&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">GH</span><span class="p">(</span><span class="n">i1</span><span class="p">)</span><span class="o">*</span><span class="n">G</span><span class="p">(</span><span class="n">i0</span><span class="p">))</span><span class="o">.</span><span class="n">canon_bp</span><span class="p">()</span>
<span class="go">G(i0)*GH(i1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">G</span><span class="p">(</span><span class="n">i1</span><span class="p">)</span><span class="o">*</span><span class="n">G</span><span class="p">(</span><span class="n">i0</span><span class="p">))</span><span class="o">.</span><span class="n">canon_bp</span><span class="p">()</span>
<span class="go">G(i1)*G(i0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">G</span><span class="p">(</span><span class="n">i1</span><span class="p">)</span><span class="o">*</span><span class="n">A</span><span class="p">(</span><span class="n">i0</span><span class="p">))</span><span class="o">.</span><span class="n">canon_bp</span><span class="p">()</span>
<span class="go">A(i0)*G(i1)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.tensor.tensor._TensorManager.set_comms">
<span class="sig-name descname"><span class="pre">set_comms</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/tensor/tensor.py#L901-L911"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.tensor.tensor._TensorManager.set_comms" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the commutation group numbers <code class="docutils literal notranslate"><span class="pre">c</span></code> for symbols <code class="docutils literal notranslate"><span class="pre">i,</span> <span class="pre">j</span></code>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>args</strong> : sequence of <code class="docutils literal notranslate"><span class="pre">(i,</span> <span class="pre">j,</span> <span class="pre">c)</span></code></p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="index_methods.html"
                        title="previous chapter">Methods</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="toperators.html"
                        title="next chapter">Tensor Operators</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/tensor/tensor.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="toperators.html" title="Tensor Operators"
             >next</a> |</li>
        <li class="right" >
          <a href="index_methods.html" title="Methods"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Tensor</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Tensor</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/tensor/tensor.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:09 GMT -->
</html>